﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class MonitoredWorkItem : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem
    {
        #region Public Members

        #region IsEnabled

        private bool _IsEnabled;
        partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsEnabledPropertyChanged();
        public bool IsEnabled
        { 
            get
            {
                return _IsEnabled;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IsEnabled = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
                    OnBeforeIsEnabledPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IsEnabled", eventData.Value, true, true);
                        OnAfterIsEnabledPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxExecutionTime

        private System.Nullable<System.TimeSpan> _MaxExecutionTime;
        partial void OnBeforeMaxExecutionTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnAfterMaxExecutionTimePropertyChanged();
        public System.Nullable<System.TimeSpan> MaxExecutionTime
        { 
            get
            {
                return _MaxExecutionTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxExecutionTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>>(value, _MaxExecutionTime);
                    OnBeforeMaxExecutionTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxExecutionTime", eventData.Value, true, true);
                        OnAfterMaxExecutionTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxExecutionTimeAlarmTimeout

        private System.Nullable<System.TimeSpan> _MaxExecutionTimeAlarmTimeout;
        partial void OnBeforeMaxExecutionTimeAlarmTimeoutPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnAfterMaxExecutionTimeAlarmTimeoutPropertyChanged();
        public System.Nullable<System.TimeSpan> MaxExecutionTimeAlarmTimeout
        { 
            get
            {
                return _MaxExecutionTimeAlarmTimeout;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxExecutionTimeAlarmTimeout = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>>(value, _MaxExecutionTimeAlarmTimeout);
                    OnBeforeMaxExecutionTimeAlarmTimeoutPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxExecutionTimeAlarmTimeout", eventData.Value, true, true);
                        OnAfterMaxExecutionTimeAlarmTimeoutPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxFailedExecutionAlarmTimeout

        private System.Nullable<System.TimeSpan> _MaxFailedExecutionAlarmTimeout;
        partial void OnBeforeMaxFailedExecutionAlarmTimeoutPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnAfterMaxFailedExecutionAlarmTimeoutPropertyChanged();
        public System.Nullable<System.TimeSpan> MaxFailedExecutionAlarmTimeout
        { 
            get
            {
                return _MaxFailedExecutionAlarmTimeout;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxFailedExecutionAlarmTimeout = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>>(value, _MaxFailedExecutionAlarmTimeout);
                    OnBeforeMaxFailedExecutionAlarmTimeoutPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxFailedExecutionAlarmTimeout", eventData.Value, true, true);
                        OnAfterMaxFailedExecutionAlarmTimeoutPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxFailedExecutionCount

        private System.Nullable<int> _MaxFailedExecutionCount;
        partial void OnBeforeMaxFailedExecutionCountPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterMaxFailedExecutionCountPropertyChanged();
        public System.Nullable<int> MaxFailedExecutionCount
        { 
            get
            {
                return _MaxFailedExecutionCount;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxFailedExecutionCount = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _MaxFailedExecutionCount);
                    OnBeforeMaxFailedExecutionCountPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxFailedExecutionCount", eventData.Value, true, true);
                        OnAfterMaxFailedExecutionCountPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxIdleTime

        private System.Nullable<System.TimeSpan> _MaxIdleTime;
        partial void OnBeforeMaxIdleTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnAfterMaxIdleTimePropertyChanged();
        public System.Nullable<System.TimeSpan> MaxIdleTime
        { 
            get
            {
                return _MaxIdleTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxIdleTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>>(value, _MaxIdleTime);
                    OnBeforeMaxIdleTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxIdleTime", eventData.Value, true, true);
                        OnAfterMaxIdleTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxIdleTimeAlarmTimeout

        private System.Nullable<System.TimeSpan> _MaxIdleTimeAlarmTimeout;
        partial void OnBeforeMaxIdleTimeAlarmTimeoutPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnAfterMaxIdleTimeAlarmTimeoutPropertyChanged();
        public System.Nullable<System.TimeSpan> MaxIdleTimeAlarmTimeout
        { 
            get
            {
                return _MaxIdleTimeAlarmTimeout;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxIdleTimeAlarmTimeout = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>>(value, _MaxIdleTimeAlarmTimeout);
                    OnBeforeMaxIdleTimeAlarmTimeoutPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxIdleTimeAlarmTimeout", eventData.Value, true, true);
                        OnAfterMaxIdleTimeAlarmTimeoutPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MonitorContextId

        private int _MonitorContextId;
        partial void OnBeforeMonitorContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<int> eventData);
        partial void OnAfterMonitorContextIdPropertyChanged();
        public int MonitorContextId
        { 
            get
            {
                return _MonitorContextId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MonitorContextId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<int> eventData = new Sidvall.Business.PropertyChangeEventData<int>(value, _MonitorContextId);
                    OnBeforeMonitorContextIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MonitorContextId", eventData.Value, true, true);
                        OnAfterMonitorContextIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MonitoredWorkItemId

        private System.Nullable<long> _MonitoredWorkItemId;
        partial void OnBeforeMonitoredWorkItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterMonitoredWorkItemIdPropertyChanged();
        public System.Nullable<long> MonitoredWorkItemId
        { 
            get
            {
                return _MonitoredWorkItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MonitoredWorkItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _MonitoredWorkItemId);
                    OnBeforeMonitoredWorkItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MonitoredWorkItemId", eventData.Value, true, true);
                        OnAfterMonitoredWorkItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SensorAlarmTimeout

        private System.Nullable<System.TimeSpan> _SensorAlarmTimeout;
        partial void OnBeforeSensorAlarmTimeoutPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData);
        partial void OnAfterSensorAlarmTimeoutPropertyChanged();
        public System.Nullable<System.TimeSpan> SensorAlarmTimeout
        { 
            get
            {
                return _SensorAlarmTimeout;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SensorAlarmTimeout = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.TimeSpan>>(value, _SensorAlarmTimeout);
                    OnBeforeSensorAlarmTimeoutPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SensorAlarmTimeout", eventData.Value, true, true);
                        OnAfterSensorAlarmTimeoutPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SensorComparisonOperator

        private global::Sidvall.Data.ComparisonOperator _SensorComparisonOperator;
        partial void OnBeforeSensorComparisonOperatorPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.Data.ComparisonOperator> eventData);
        partial void OnAfterSensorComparisonOperatorPropertyChanged();
        public global::Sidvall.Data.ComparisonOperator SensorComparisonOperator
        { 
            get
            {
                return _SensorComparisonOperator;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SensorComparisonOperator = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<global::Sidvall.Data.ComparisonOperator> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.Data.ComparisonOperator>(value, _SensorComparisonOperator);
                    OnBeforeSensorComparisonOperatorPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SensorComparisonOperator", eventData.Value, true, true);
                        OnAfterSensorComparisonOperatorPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SensorName

        private string _SensorName;
        partial void OnBeforeSensorNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSensorNamePropertyChanged();
        public string SensorName
        { 
            get
            {
                return _SensorName;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SensorName = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _SensorName);
                    OnBeforeSensorNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SensorName", eventData.Value, true, true);
                        OnAfterSensorNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SensorValue

        private string _SensorValue;
        partial void OnBeforeSensorValuePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSensorValuePropertyChanged();
        public string SensorValue
        { 
            get
            {
                return _SensorValue;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SensorValue = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _SensorValue);
                    OnBeforeSensorValuePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SensorValue", eventData.Value, true, true);
                        OnAfterSensorValuePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkItemId

        private System.Nullable<long> _WorkItemId;
        partial void OnBeforeWorkItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterWorkItemIdPropertyChanged();
        public System.Nullable<long> WorkItemId
        { 
            get
            {
                return _WorkItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _WorkItemId);
                    OnBeforeWorkItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkItemId", eventData.Value, true, true);
                        OnAfterWorkItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public MonitorContext MonitorContext { get; set; }
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public MonitoredWorkItem Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.Copy(this);
        }
        public MonitoredWorkItem Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem item)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.Initialize(this, settings);
        }

        #endregion

        #region IMonitoredWorkItem Members

        bool global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.IsEnabled
        {
            get
            {
                return this._IsEnabled;
            }
            set
            {
                this._IsEnabled = value;
            }
        }
        System.Nullable<System.TimeSpan> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MaxExecutionTime
        {
            get
            {
                return this._MaxExecutionTime;
            }
            set
            {
                this._MaxExecutionTime = value;
            }
        }
        System.Nullable<System.TimeSpan> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MaxExecutionTimeAlarmTimeout
        {
            get
            {
                return this._MaxExecutionTimeAlarmTimeout;
            }
            set
            {
                this._MaxExecutionTimeAlarmTimeout = value;
            }
        }
        System.Nullable<System.TimeSpan> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MaxFailedExecutionAlarmTimeout
        {
            get
            {
                return this._MaxFailedExecutionAlarmTimeout;
            }
            set
            {
                this._MaxFailedExecutionAlarmTimeout = value;
            }
        }
        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MaxFailedExecutionCount
        {
            get
            {
                return this._MaxFailedExecutionCount;
            }
            set
            {
                this._MaxFailedExecutionCount = value;
            }
        }
        System.Nullable<System.TimeSpan> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MaxIdleTime
        {
            get
            {
                return this._MaxIdleTime;
            }
            set
            {
                this._MaxIdleTime = value;
            }
        }
        System.Nullable<System.TimeSpan> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MaxIdleTimeAlarmTimeout
        {
            get
            {
                return this._MaxIdleTimeAlarmTimeout;
            }
            set
            {
                this._MaxIdleTimeAlarmTimeout = value;
            }
        }
        int global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MonitorContextId
        {
            get
            {
                return this._MonitorContextId;
            }
            set
            {
                this._MonitorContextId = value;
            }
        }
        System.Nullable<long> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MonitoredWorkItemId
        {
            get
            {
                return this._MonitoredWorkItemId;
            }
            set
            {
                this._MonitoredWorkItemId = value;
            }
        }
        System.Nullable<System.TimeSpan> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.SensorAlarmTimeout
        {
            get
            {
                return this._SensorAlarmTimeout;
            }
            set
            {
                this._SensorAlarmTimeout = value;
            }
        }
        global::Sidvall.Data.ComparisonOperator global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.SensorComparisonOperator
        {
            get
            {
                return this._SensorComparisonOperator;
            }
            set
            {
                this._SensorComparisonOperator = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.SensorName
        {
            get
            {
                return this._SensorName;
            }
            set
            {
                this._SensorName = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.SensorValue
        {
            get
            {
                return this._SensorValue;
            }
            set
            {
                this._SensorValue = value;
            }
        }
        System.Nullable<long> global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.WorkItemId
        {
            get
            {
                return this._WorkItemId;
            }
            set
            {
                this._WorkItemId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IMonitorContext global::Sidvall.WorkItemManager.Data.IMonitoredWorkItem.MonitorContext
        {
            get
            {
                return this.MonitorContext;
            }
            set
            {
                this.MonitorContext = (MonitorContext)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public MonitoredWorkItem()
        {
        }
        public MonitoredWorkItem(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public MonitoredWorkItem(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.MonitoredWorkItemManager.Initialize(this);
        }

        #endregion
    }
}